<?php
class OtherController extends Controller{
public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			'postOnly + delete', // we only allow deletion via POST request
		);
	}

	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('index','view','lrsuccessfull'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform 'create' and 'update' actions
				'actions'=>array('checkimei'),
				'users'=>array('@'),
			),
			array('allow', // allow admin user to perform 'admin' and 'delete' actions
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
	
	public function actionCheckImei(){
		$model = new ImeiForm;
		
		if (isset($_POST['ImeiForm'])){
			$model->attributes = $_POST['ImeiForm'];
			$model->result = '';
			$url = 'http://www.iphoneyeta.org/icarrierapi.php';
			$postdata = "imei=".$model->imei."&id=KqdXV9l7jQ3WhAZUlAFT&emailadd=vnunlockcare@yahoo.com";
			$ch = curl_init();
			curl_setopt($ch,CURLOPT_URL,$url);
			curl_setopt($ch,CURLOPT_POST,1); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
			curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
			$resultserver = curl_exec($ch);
			$field = json_decode($resultserver,true);
				if (isset($field['error'])){
				$model->result .= $field['error'];
				}else{
				$model->result .= "Device: ".$field['device']."\n";
				$model->result .="IMEI: ".$field['imei']."\n";
				$model->result .= "Serial: ".$field['serial']."\n";
				$model->result .= "Mac Address: ".$field['macaddress']."\n";
				$model->result .= "Version: ".$field['version']."\n";
				$model->result .= "Warranty: ".$field['warranty']."\n";
				$model->result .= "Country: ".$field['purchasecountry']."\n";
				$model->result .= "Activated: ".$field['isactivated']."\n";
				$model->result .= "First Activation: ".$field['firstactivedate']."\n";
				$model->result .= "Last Activation: ".$field['lastactivedate']."\n";
				$model->result .= "Operator: ".$field['operator']."\n";
				$model->result .= "Network: ".$field['network']."\n";
				$model->result .= "Lock Status: ".$field['lockstatus']."\n";
				$model->result .= "Next Tether Policy: ".$field['nexttetherpolicy']."\n";
				//this will show the remaining checks of your account
				$model->result .= "Remain Checks: ".$field['remainchecks']."\n"; //make a function if your checks is below 5 or 0.
				//example 
				// if remain checks it 0 then do an action like printing "please contact the administrator"
				
			}
		}
			
		$this->render('checkimei',array( 'model'=>$model));
	}
}